package com.example.backend.service;

import com.example.backend.entity.Book;
import com.example.backend.entity.Post;
import com.example.backend.mapper.PostMapper;
import com.example.backend.mapper.UserMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PostService {

    private PostMapper postMapper;

    @Autowired
    public PostService(PostMapper postMapper){
        this.postMapper=postMapper;
    }

    public List<Post> getAllPosts(){
        List<Post> posts=postMapper.getAllPosts();
        return posts;
    }

    public boolean addPosts(@Param("postId") int id, @Param("userId") int id2, @Param("title") String title, @Param("content") String content, @Param("date") String date){
        int post = postMapper.addPosts(id,id2,title,content,date);
        if(post == 0)
            return false;
        else
            return true;
    }

    public List<Post> getPosts (@Param("title") String title){
        List<Post> posts = postMapper.getPosts(title);
        return posts;
    }

   public boolean deletePosts(@Param("postId") int id){
        int post = postMapper.deletePosts(id);
        if (post == 0)
            return false;
        else
            return true;
    }

   public boolean updatePosts(@Param("postId") int id,@Param("postId") int id2,@Param("title") String title,@Param("content") String content,@Param("date") String date){
       int post = postMapper.updatePosts(id,id2,title,content,date);
       if (post == 0)
           return false;
       else
           return true;
    }

}
